<?php

class TaxonomyWidget extends CWidget{
    
    public function run() {
        parent::run();
        $output = "";
        $Taxonomy = Taxonomy::model()->findByPk(1);
        $this->loopNode($output, $Taxonomy,null,"");
        $this->render('Taxonomy',array('output' => $output));
    }
    
    /**
     * show element
     * @return type 
     */
    private function loopNode(&$output,$Taxonomy,$parent,$prefix,$spear = "--"){
        if($Taxonomy != null){
            $newPrefix = "";
            if($Taxonomy->id != 1 && $parent != null){
                ob_start();
                $this->render('ElementTaxonomy',array('parent' => $parent,'taxonomy' => $Taxonomy,'prefix' => $prefix,'spear' => $spear));
                $out1 = ob_get_contents();
                ob_end_clean();
                $output .= $out1;
                $newPrefix = $prefix.$spear;
            }
            $children = $Taxonomy->children()->findAll(array('order'=>'orders ASC'));
            foreach($children as $child){
                $this->loopNode($output, $child,$Taxonomy,$newPrefix,$spear);
            }
        }
    }
}
